<?php
class AppHelper extends Helper {


	
	function url($url = null, $full = false) {

		if(!isset($url['language'])){

			if(isset($this->params['language'])){
				$url['language'] = $this->params['language'];
			}else{
				$url['language'] = Configure::read('Config.language');
			}
		}	
		return parent::url($url, $full);
	}
	
	/**
	 * 
	 * CSS style block in header
	 * @param unknown_type $script
	 * @param unknown_type $options
	 */
	
	function styleBlock($script, $options = array()) {
		$options += array('safe' => false, 'inline' => true);
		if ($options['safe']) {
			$script  = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
		}
		$inline = $options['inline'];
		unset($options['inline'], $options['safe']);
		$attributes = $this->_parseAttributes($options, ' ', ' ');
		if ($inline) {
			return sprintf('<style type="text/css"%s>%s</style>', $attributes, $script);
		} else {
			$view =& ClassRegistry::getObject('view');
			$view->addScript(sprintf('<style type="text/css"%s>%s</style>', $attributes, $script));
			return null;
		}
	}

	/**
	 * JQuery dialog
	 * 
	 * @param unknown_type $object
	 * @param unknown_type $params
	 * @param unknown_type $options
	 */
	public function dialog($object,$params=array(), $options = array()){
		$options += array('safe' => false, 'inline' => false);
		$patams = json_encode($params);
		$script = "$(document).ready(function(){
				$( '{$object}' ).dialog({$patams});
			});";
					
		if ($options['safe']) {

			$script  = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
		}
		$inline = $options['inline'];
		unset($options['inline'], $options['safe']);
		$attributes = $this->_parseAttributes($options, ' ', ' ');
		if ($inline) {
			return sprintf('<script type="text/javascript"%s>%s</script>', $attributes, $script);
		} else {
			$view =& ClassRegistry::getObject('view');
			$view->addScript(sprintf('<script type="text/javascript"%s>%s</script>', $attributes, $script));
			return null;
		}		
	}
	
	function timeFormaPL($format='l j F Y',$date=False){
// 		$date = (is_numeric($date)?$date:time());
		$date = strtotime($date);
	
		$m=array(1=>'styczeń','luty','marzec','kwiecień','maj','czerwiec',
	     'lipiec','sierpień','wrzesień','październik','listopad','grudzień');
		$ms=array(1=>'sty','lut','mar','kwi','maj','cze',
	     'lip','sie','wrz','paź','lis','gru');
		$md=array(1=>'stycznia','lutego','marca','kwietnia','maja','czerwca',
	     'lipca','sierpnia','września','października','listopada','grudnia');
		$d=array(0=>'Niedziela','Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota');
		$ds=array(0=>'Nd','Pn','Wt','Śr','Cz','Pt','So');
	
		$f = str_split($format);
		for($i=0;$i<count($f);$i++){
			if($f[$i]!="\\"){
				switch($f[$i]){
					case 'F':
						$f[$i] = $md[date('n',$date)];
						break;
					case 'f':
						$f[$i] = $m[date('n',$date)];
						break;
					case 'M':
						$f[$i] = $ms[date('n',$date)];
						break;
					case 'l':
						$f[$i] = $d[date('w',$date)];
						break;
					case 'D':
						$f[$i] = $ds[date('w',$date)];
						break;
					default:
						$f[$i] = date($f[$i],$date);
				}
	
			}else{
				$f[$i]='';
				$i++;
			}
		}
		return implode('',$f);
	}
}